package com.chen.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.springboot.common.Result;
import com.chen.springboot.entity.RefundOrder;
import com.chen.springboot.service.RefundOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @Author: Chen
 * @Date: 2024/3/5  15:34
 */
@Api(tags = {"退款订单接口"})
@RestController
@RequestMapping("/refund")
public class RefundOrderController {

    @Autowired
    private RefundOrderService refundOrderService;

    @ApiOperation("查询所有退款订单")
    @GetMapping
    public Result<?> getAll(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            @RequestParam(defaultValue = "") String search) {
        Page<RefundOrder> refundOrders =  refundOrderService.getAll(pageNum,pageSize,search);
        return Result.success(refundOrders);
    }

    @ApiOperation("删除退款订单")
    @DeleteMapping("/{id}")
    public Result<?> deleteOne(@PathVariable("id") Integer id) {
        refundOrderService.deleteOne(id);
        return Result.success();
    }

    @ApiOperation("下载excel图表")
    @GetMapping("/download")
    public void download(HttpServletResponse response) {
        refundOrderService.download(response);
    }

    @ApiOperation("完成退款")
    @PostMapping("/unshipped")
    public Result<?> refunded(@RequestBody RefundOrder refundOrder) {
        refundOrderService.refunded(refundOrder);
        return Result.success();
    }

    @ApiOperation("更改状态为退款中")
    @PostMapping("/shipped")
    public Result<?> refunding(@RequestBody RefundOrder refundOrder) {
        refundOrderService.refunding(refundOrder);
        return Result.success();
    }

    @ApiOperation("更新退款时间")
    @PutMapping("/time/{orderNo}")
    public Result<?> refundTime(@PathVariable String orderNo) {
        refundOrderService.refundTime(orderNo);
        return Result.success();
    }
}
